$file2 = $ARGV[0];
$file1 = $ARGV[1];
open(BUFF2,$file2);
open(BUFF1,$file1);
open(BUFF3,$file1);
open(WRBUFF,">equal_probes_ori_$file1");

while($line = <BUFF1>)
{
	if($line =~ m/Cell(\d+)/ && $line =~ m/control/)
	{
		@line = split("\t",$line);
		@liney = split("\=",$line[0]);
		
#		print WRBUFF $liney[1]."\t".$line[1]."\n";
		$line[1] =~ s/\s//g;
		$line[1] =~ s/\n//g;
		$line[1] =~ s/\r//g;
		$liney[1] =~ s/\s//g;
                $liney[1] =~ s/\n//g;
                $liney[1] =~ s/\r//g;
		$hash{$liney[1]."\t".$line[1]} = "k";
		
	}
}
while($line = <BUFF3>)
{
	print WRBUFF $line;
}
$n = 1;
$n1 = 1;
$numnew = 12551;
$k = 1;
$numnew1 = 9000001;
				print WRBUFF "\n";
                                print WRBUFF "\n";
                                print WRBUFF "[Unit".$numnew."]"."\n";
                                print WRBUFF "Name=NONE"."\n";
                                print WRBUFF "Direction=2"."\n";
                                print WRBUFF "NumAtoms=10"."\n";
                                print WRBUFF "NumCells=20"."\n";
                                print WRBUFF "UnitNumber=".$numnew."\n";
                                print WRBUFF "UnitType=3"."\n";
				print WRBUFF "NumberBlocks=1"."\n";
                                print WRBUFF "\n";
                                print WRBUFF "[Unit".$numnew."_Block1]"."\n";
                                print WRBUFF "Name="."$numnew1"."\n";
                                print WRBUFF "BlockNumber=1"."\n";
                                print WRBUFF "NumAtoms=10"."\n";
                                print WRBUFF "NumCells=20"."\n";
                                print WRBUFF "StartPosition=1"."\n";
                                print WRBUFF "StopPosition=10"."\n";
                                print WRBUFF "CellHeader=X\tY\tPROBE\tFEAT\tQUAL\tEXPOS\tPOS\tCBASE\tPBASE\tTBASE\tATOM\tINDEX\tCODONIND\tCODON\tREGIONTYPE\tREGION\n";

while($line = <BUFF2>)
{
        if($line =~ m/Cell(\d+)/ && $line =~ m/control/)
        {
                @line = split("\t",$line);
                @liney = split("\=",$line[0]);
#		$line[4] = 987654321987654321;
#               print WRBUFF $liney[1]."\t".$line[1]."\n";
		 $line[1] =~ s/\s//g;
                $line[1] =~ s/\n//g;
                $line[1] =~ s/\r//g;
                $liney[1] =~ s/\s//g;
                $liney[1] =~ s/\n//g;
                $liney[1] =~ s/\r//g;
                if($hash{$liney[1]."\t".$line[1]} eq "k")
		{
			

		}
		else
		{
			if($k > 20)
			{
				

				$numnew++;
				$numnew1++;
				$k = 1;
				$n = 1;
				$n1 = 1;
				print WRBUFF "\n";
				print WRBUFF "\n";
				print WRBUFF "[Unit".$numnew."]"."\n";
				print WRBUFF "Name=NONE"."\n";
				print WRBUFF "Direction=2"."\n";
				print WRBUFF "NumAtoms=10"."\n";
				print WRBUFF "NumCells=20"."\n";
				print WRBUFF "UnitNumber=".$numnew."\n";
				print WRBUFF "UnitType=3"."\n";
				 print WRBUFF "NumberBlocks=1"."\n";
				print WRBUFF "\n";
				print WRBUFF "[Unit".$numnew."_Block1]"."\n";
				print WRBUFF "Name="."$numnew1"."\n";
				print WRBUFF "BlockNumber=1"."\n";
				print WRBUFF "NumAtoms=10"."\n";
                                print WRBUFF "NumCells=20"."\n";
				print WRBUFF "StartPosition=1"."\n";
				print WRBUFF "StopPosition=10"."\n";
				print WRBUFF "CellHeader=X\tY\tPROBE\tFEAT\tQUAL\tEXPOS\tPOS\tCBASE\tPBASE\tTBASE\tATOM\tINDEX\tCODONIND\tCODON\tREGIONTYPE\tREGION\n";
			}				
			$line[4] = $numnew1;
			$line[5] = $n;
			$line[10] = $n;	
#			print "success\n";
			$len = @line-1;
			if($line[$len] eq "")
			{
				pop(@line);
			}
			$line = join("\t",@line);
			$line =~ s/\n//g;
			$line =~ s/\r//g;
			print WRBUFF $line."\n";
			if($n1%2 == 0)
			{
				$n++;
			}
			$n1++;
			$k++;
		}

        }
}
#print $n."\t".$n1;
